// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets;

import java.nio.ByteBuffer;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.iso.objects.IsoDeadBody;

public class RemoveCorpseFromMap implements INetworkPacket {
    private short id;
    private IsoDeadBody deadBody = null;

    public void set(IsoDeadBody _deadBody) {
        this.id = _deadBody.getObjectID();
        this.deadBody = _deadBody;
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        this.id = b.getShort();
        this.deadBody = IsoDeadBody.getDeadBody(this.id);
    }

    @Override
    public void write(ByteBufferWriter b) {
        b.putShort(this.id);
    }

    public void process() {
        if (this.isConsistent()) {
            IsoDeadBody.removeDeadBody(this.id);
        }
    }

    @Override
    public String getDescription() {
        return String.format(this.getClass().getSimpleName() + " id=%d", this.id);
    }

    @Override
    public boolean isConsistent() {
        return this.deadBody != null && this.deadBody.getSquare() != null;
    }

    public boolean isRelevant(UdpConnection connection) {
        return connection.RelevantTo(this.deadBody.getX(), this.deadBody.getY());
    }
}
